home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Gekkan Dennou Club 147
/
Gekkan Dennou Club - 2000.8 Vol. 147 (Japan).7z
/
Gekkan Dennou Club - 2000.8 Vol. 147 (Japan) (Track 1).bin
/
tools
/
pecls
/
wfd.c
< prev
next >
Wrap
C/C++ Source or Header
|
1999-10-06
|
3KB
|
139 lines
/*
* PECLS Operating System
* (Parallel Execute Control Learning System)
* Copyright (C) 1994,95,96,98,99 M.Suzuki
*
* FD writer
*
*/
/*
*
* $Id: wfd.c,v 1.1 1999/08/27 19:30:17 suzuki Exp suzuki $
*
* $Log: wfd.c,v $
* Revision 1.1 1999/08/27 19:30:17 suzuki
* Initial revision
*
*
*/
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#include <stat.h>
#include <string.h>
#include <iocslib.h>
#define False 0
#define True (!False)
#define PR(x) /* none */
#define Null(x) /* none */
#define SECTOR_SIZE 3 /* 0,128,1:256,2:512,3:1024 */
#define _UM(x) (((unsigned int)(x))&0x0ff)
#define RECNO(a,b,c,d) ((_UM(a)<<24)|(_UM(b)<<16)|(_UM(c)<<8)|_UM(d))
int Swrite(int drive, int pos, int len, void* buff)
{
unsigned int ret;
int side;
int track;
int sec;
Null(buff);
drive <<= 8;
drive |= 0x70; /* 倍密/Retryあり/Seekあり */
side = (pos>>3)&1;
track = pos>>4;
sec = (pos&0x07)+1;
PR(("pos[%d] side[%d] track[%d] sec[%d]\n",pos,side,track,sec));
/* ret = B_SEEK(drive,RECNO(SECTOR_SIZE,track,side,sec));
if( (ret & 0x0ffffff00) == 0x0ffffff00 ){
printf("B_SEEK error [%08x]\n",ret);
return False;
} */
ret = B_WRITE(drive,RECNO(SECTOR_SIZE,track,side,sec),len*1024,buff);
if( (ret & 0x0ffffff00) == 0x0ffffff00 ){
printf("B_WRITE error [%08x]\n",ret);
return False;
}
PR(("Normal end\n"));
return True;
}
int MainLoop(char* fname, int drive)
{
unsigned char program[1024];
unsigned int size;
unsigned int i;
FILE* fp;
if( (fp=fopen(fname,"rb")) == NULL ){
printf("%s がオープン出来ません。\n",fname);
return False;
}
{
struct stat st;
fstat(fileno(fp),&st);
size = st.st_size;
}
for(i=0;size;i++){
int len;
if( size >= 1024 ){
len = 1024;
size -= 1024;
} else {
memset(program,0,1024);
len = size;
size = 0;
}
if( fread(program,len,1,fp) != 1 ){
fclose(fp);
printf("ファイルが読めませんでした。\n");
return False;
}
printf("write %4d",i);
if( Swrite(drive,i,1,program) == False ){
printf("ディスクに書けませんでした。\n");
return False;
}
printf("\r");
} /* end of for */
fclose(fp);
printf("\r書き込み完了\n");
return True;
}
int main(int argc, char* argv[])
{
char* fname = "ipl.r";
int drive = 0x90;
int i;
allmem();
for(i=1;i<argc;i++){
char* p;
p = argv[i];
if( *p == '-' ){
p++;
if( *p == 'd'){
p++;
if( isdigit(*p) ){
drive = atoi(p) + 0x90;
} else
if( i+1 < argc ){
i++;
drive = atoi(argv[i]) + 0x90;
}
}
} else {
fname = p;
}
} /* end of for */
return (MainLoop(fname,drive)==True)?0:1;
}